{% extends 'layout/base.html' %}

{% block content %}
<div class="row mt-5">
    <div class="col-lg-3">
        {% set active_nav = 'dns' %}
        {% include 'config/includes/sidebar.html' %}
    </div>
    <div class="col-lg-6">
        <form action="{{ url_for('config.dns_save') }}" method="post">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            <h4>DNS Base Domain</h4>
            <div>
                <small>
                    The Base Domain is the domain under which all users will be able to create personalised addresses.
                    The format will be <i>%username%.snitch.example.com</i>.
                </small>
            </div>
            <div class="form-group row">
                <div class="col">
                    <label for="dns_base_domain">Domain</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="dns_base_domain" id="dns_base_domain" value="{{ setting_get('dns_base_domain', '') }}" placeholder="snitch.example.com" autofocus required>
                </div>
            </div>

            <h4 class="mt-4">DNS Daemon</h4>
            <div class="form-group row">
                <div class="col">
                    <label for="dns_daemon_bind_ip">Bind Local IP Address</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="dns_daemon_bind_ip" id="dns_daemon_bind_ip" value="{{ setting_get('dns_daemon_bind_ip', '') }}" placeholder="Local IP or 0.0.0.0" required>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="dns_daemon_bind_port">Bind Local Port</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="dns_daemon_bind_port" id="dns_daemon_bind_port" value="{{ setting_get('dns_daemon_bind_port', '') }}" placeholder="between 1024 and 65535" required>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="dns_daemon_start_everyone">Allow all users to start the service</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="dns_daemon_start_everyone" type="checkbox" class="custom-control-input" id="dns_daemon_start_everyone" value="1" {{ 'checked' if setting_get('dns_daemon_start_everyone', False) == True }}>
                        <label class="custom-control-label" for="dns_daemon_start_everyone"></label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="dns_cache_enabled">Enable DNS Caching</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="dns_cache_enabled" type="checkbox" class="custom-control-input" id="dns_cache_enabled" value="1" {{ 'checked' if setting_get('dns_cache_enabled', False) == True }}>
                        <label class="custom-control-label" for="dns_cache_enabled"></label>
                    </div>
                </div>
            </div>

            <h4 class="mt-4">DNS Forwarding</h4>
            <div class="form-group row">
                <div class="col">
                    <label for="forward_dns_enabled">Enable DNS Forwarding</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="forward_dns_enabled" type="checkbox" class="custom-control-input" id="forward_dns_enabled" value="1" {{ 'checked' if setting_get('forward_dns_enabled', False) == True }}>
                        <label class="custom-control-label" for="forward_dns_enabled"></label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="forward_dns_address">Forward DNS Servers</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="forward_dns_address" id="forward_dns_address" value="{{ setting_get('forward_dns_address', '') }}" placeholder="8.8.8.8, 8.8.4.4">
                </div>
            </div>

            <h4 class="mt-4">DNS CSV Logging</h4>
            <div class="form-group row">
                <div class="col">
                    <label for="csv_logging_enabled">Enable CSV Logging</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="csv_logging_enabled" type="checkbox" class="custom-control-input" id="csv_logging_enabled" value="1" {{ 'checked' if setting_get('csv_logging_enabled', False) == True }}>
                        <label class="custom-control-label" for="csv_logging_enabled"></label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="csv_logging_file">CSV Output Location</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="csv_logging_file" id="csv_logging_file" value="{{ setting_get('csv_logging_file', '') }}" placeholder="/var/log/snitch/log.csv">
                </div>
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-block btn-primary">save</button>
                <div class="small text-warning text-center">For any changes to this page to be applied, the DNS Daemon has to be restarted.</div>
            </div>
        </form>
    </div>
    <div class="col"></div>
</div>
{% endblock %}